package com.hui.server.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.hui.server.entity.Admin;
import com.hui.server.entity.Menu;
import com.hui.server.mapper.MenuMapper;
import com.hui.server.service.MenuService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author hui
 * @since 2022-03-31
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {

    private MenuMapper mapper;


    @Autowired
    public MenuServiceImpl(MenuMapper mapper) {
        this.mapper = mapper;
    }

    /**
     * 通过用户ID查询菜单列表，使用到了Redis缓存
     * @return
     */
    @Override
    public List<Menu> getMenusByAdminId() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        Admin admin = (Admin) authentication.getPrincipal();

        return mapper.getMenusByAdminId(admin.getId());
    }


    /**
     *  查询所有角色拥有的所有菜单
     * @return
     */
    @Override
    public List<Menu> getMenusByRoles() {
        return mapper.getMenusByRoles();
    }


    /**
     * 获取所有菜单
     * @return
     */
    @Override
    public List<Menu> getAllMenus() {
        return mapper.getAllMenus();
    }


}
